export function setStorage(key: string, value: any) {
  const data = JSON.stringify(value);
  if (process.env.isMiniprogram) {
    //@ts-ignore
    wx.setStorageSync(key, data);
  } else {
    window.localStorage.setItem(key, data);
  }
}

export function getStorage(key: string) {
  let res = null;
  if (process.env.isMiniprogram) {
    //@ts-ignore
    res = wx.getStorageSync(key);
  } else {
    res = window.localStorage.getItem(key);
  }
  if (res) {
    return JSON.parse(res);
  }
  return null;
}

export function clearStorage(key: string) {
  let res: any = null;
  if (process.env.isMiniprogram) {
    //@ts-ignore
    res = wx.removeStorageSync(key);
  } else {
    res = window.localStorage.removeItem(key);
  }
  if (res) {
    return JSON.parse(res);
  }
  return null;
}
